//
//  HomePageHotHouseTableVIewCell.m
//  PersonalProjects
//
//  Created by lanou3g on 15/9/11.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "HomePageHotHouseTableVIewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "MBProgressHUD.h"
#import "YPKLocalDataManager.h"

@implementation HomePageHotHouseTableVIewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}

- (IBAction)favoriteTheHouse:(id)sender {
    /**
     *  收藏点击方法（默认为空心不收藏，点击收藏，再次点击取消收藏）
     */
    
        BOOL isFavorited = [[YPKLocalDataManager getInstance] queryHouseIsFavoritedWithHouseId:_homePageHouseModel.houseId];
    if (isFavorited) {
        [[YPKLocalDataManager getInstance] deleteFavoriteWithHouseId:_homePageHouseModel.houseId];
        [_favoriteButton setImage:[UIImage imageNamed:@"room_details_collect_2"] forState:UIControlStateNormal];
        [self showReminberViewWithString:@"取消收藏"];
    }else{
        [[YPKLocalDataManager getInstance] insertFavoriteWithInfo:_homePageHouseModel];
        [_favoriteButton setImage:[UIImage imageNamed:@"room_details_collect_1"] forState:UIControlStateNormal];
        [self showReminberViewWithString:@"收藏成功"];
    }
}

- (void)setItems:(HomePageHouseModel *)homePageHouseModel
{
    _simpleImageViewHeight.constant = SCREEN_WIDTH/2;
    _homePageHouseModel = homePageHouseModel;
    _landmarkLabel.text = homePageHouseModel.landmarkName;
    _titleLabel.text = homePageHouseModel.title;
    BOOL isFavorited = [[YPKLocalDataManager getInstance] queryHouseIsFavoritedWithHouseId:homePageHouseModel.houseId];
    if (isFavorited) {
        [_favoriteButton setImage:[UIImage imageNamed:@"room_details_collect_1"] forState:UIControlStateNormal];
    }else{
        [_favoriteButton setImage:[UIImage imageNamed:@"room_details_collect_2"] forState:UIControlStateNormal];
    }
    
    [_simpleImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@%@",kImageURL,homePageHouseModel.imgURLString]] placeholderImage:[UIImage imageNamed:@"default_img"]];
    _titleLabel.text = homePageHouseModel.title;
//    if ([homePageHouseModel.houseType isEqualToString:@"1"])
//    {
//        if (!homePageHouseModel.specialPriceStatus) {
//            _shortPriceLabel.text = [NSString stringWithFormat:@"%@",homePageHouseModel.price];
//            _priceLabelWidth.constant = homePageHouseModel.price.length*10+10;
//        }else{
//            _shortPriceLabel.text = [NSString stringWithFormat:@"%@",homePageHouseModel.specialPrice];
//            _priceLabelWidth.constant = homePageHouseModel.specialPrice.length*10+10;
//        }
//        _unitLabel.text = @"/晚";
//    }else if([homePageHouseModel.houseType isEqualToString:@"2"]){
//        if (!homePageHouseModel.specialPriceStatus) {
//            _shortPriceLabel.text = [NSString stringWithFormat:@"%@",homePageHouseModel.longPrice];
//            _priceLabelWidth.constant = homePageHouseModel.longPrice.length*10+10;
//        }else{
//            _shortPriceLabel.text = [NSString stringWithFormat:@"%@",homePageHouseModel.specialPrice];
//            _priceLabelWidth.constant = homePageHouseModel.specialPrice.length*10+10;
//        }
//        _unitLabel.text = @"/月";
//        
//    }else{
//        if (!homePageHouseModel.specialPriceStatus) {
//            _shortPriceLabel.text = [NSString stringWithFormat:@"%@",homePageHouseModel.middlePrice];
//            _priceLabelWidth.constant = homePageHouseModel.middlePrice.length*10+10;
//        }else{
//            _shortPriceLabel.text = [NSString stringWithFormat:@"%@",homePageHouseModel.specialPrice];
//            _priceLabelWidth.constant = homePageHouseModel.specialPrice.length*10+10;
//        }
//        _unitLabel.text = @"/月";
//    }
    
}

- (void)showReminberViewWithString:(NSString *)string {
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:_viewController.navigationController.view];
    [_viewController.navigationController.view addSubview:hud];
    // Set custom view mode
    hud.mode = MBProgressHUDModeCustomView;
    hud.labelText = string;
    [hud show:YES];
    [hud hide:YES afterDelay:0.7];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
